import { DB } from '../share/share'

async function initFetch () {
  let fileArray = [
    '/mimetype',
    '/META-INF/container.xml',
    '/OEBPS/Styles/style.css',
    '/OEBPS/Text/cover.xhtml',
    '/OEBPS/Text/coverAlt.xhtml',
    '/OEBPS/Text/contents.xhtml',
    '/OEBPS/Text/contents-img.xhtml',
    '/OEBPS/Text/Color001-1.xhtml',
    '/OEBPS/Text/Color001.xhtml',
    '/OEBPS/Text/Section001.xhtml',
    '/OEBPS/Text/Summary.xhtml',
    '/OEBPS/Text/License.xhtml',
    '/OEBPS/content.opf',
    '/OEBPS/toc.ncx',
    '/OEBPS/Misc/notereplace.js'
  ]

  for (const item of fileArray) {
    let fileRes = await fetch(`../../Template${item}`)
    let fileSource = await fileRes.text()
    let fileNameMatch = item.match(/.*\/(.*?)$/)
    let fileName = fileNameMatch[fileNameMatch.length - 1]
    await DB.template.put({name: fileName, path: item, source: fileSource})
  }
}

export default initFetch
